<h2> Liste des devis</h2>

<table id="t_devis">
	<thead>
    	<tr>
    		<th> ID </th>
            <th> Client </th>
            <th> Date </th>
            <th> Montant TTC </th>
    		<th></th>
    	</tr>
    </thead>
	<?foreach($devis as $d){
		$client = $aContacts[$d->contact_id];
		$client_name = $client->prenom." ".$client->nom;
		if($client->societe != "")
			$client_name .= " (".$client->societe.")";
	?>
        <tr>
        	<td><?=$d->_id?></td>
            <td><?=$client_name?></td>
            <td><?=date("d-m-Y",strtotime($d->date))?></td>
            <td><?=$d->montant_ttc?> &euro;</td>
            <td>
            	<a href="/ventes/devis/download/<?=$d->_id?>" target="_blank"><img src="/public/images/icons/pdf.png" title="Télécharger le devis"/></a>
            	<?if(!isset($aDevisFactures[$d->_id])){?>
            		<a href="javascript:editDevis('<?=$d->_id?>');"><img src="/public/images/icons/edit.png" title="Modifier le devis"/></a>
	            	<a href="javascript:removeDevis('<?=$d->_id?>');"><img src="/public/images/icons/remove.png" title="Supprimer le devis"/></a>
	            	<a href="javascript:facturerDevis('<?=$d->_id?>');"><img src="/public/images/icons/ok.png" title="Transformer le devis en facture"/></a>
	            <?}?>
	            <a href="javascript:previewDevis('<?=$d->_id?>');"><img src="/public/images/icons/preview.png" title="Aperçu"/></a>
            </td>
    	</tr>
	<?}?>
</table>
<br/>
<center>
	<button onclick="$('#nouveau_devis').dialog('open');" id="bouttonNew"> Nouveau devis </button>
</center>

<div id="nouveau_devis" title="Création d'un devis">
	<?=$this->inc("ventes/form_devis",array("aContacts"=>$aContacts,"typesReglements"=>$typesReglements,"aTVA"=>$aTVA,"planComptable"=>$planComptable));?>
</div>
<div id="newDevisOK_dial">
	Nouveau devis enregistré
</div>
<?if(isset($_GET["client_id"])){?>
<script>
$(document).ready(function() {
	$("#contact_<?=$_GET["client_id"]?>").attr("checked",true);
	$( "#crer_devis_tabs" ).tabs("select", 1 );
	$('#nouveau_devis').dialog('open');
});
</script>
<?}?>